import { Tabs, Typography, Card } from 'antd';
import { useSearchParams } from 'react-router-dom';

import { useState, useEffect } from 'react';
import type { SchoolItem } from '../../../types/school';
import { getSchoolDetail } from '../../../api/school';

const { Title } = Typography;
const { TabPane } = Tabs;

const SchoolDetail = () => {
    const [searchParams] = useSearchParams();
    const schoolId = searchParams.get('id');
    const [school, setSchool] = useState<SchoolItem | null>(null);
    const [loading, setLoading] = useState(true);

    useEffect(() => {
        // 调用接口获取学校详情
        if (!schoolId) {
            setLoading(false);
            return;
        }
        setLoading(true);
        getSchoolDetail(Number(schoolId)).then(res => {
            console.log(res)
            setSchool(res);

        }).catch(err => {
            console.error('获取学校详情失败', err);
        }).finally(() => setLoading(false))
    }, [schoolId]);

    return (
        <div>
            {/* 显示当前学校名称，强化上下文感知 */}
            <Title level={4} style={{ marginBottom: 20 }}>
                {school?.name} 管理中心
            </Title>

            <Card>
                <Tabs defaultActiveKey="info" size="large">
                    <TabPane tab="学校基本信息" key="info">
                        <div>1</div>
                    </TabPane>
                    <TabPane tab="年级管理" key="grades">
                        <div>2</div>
                    </TabPane>
                    <TabPane tab="班级管理" key="classes">
                        <div>3</div>
                    </TabPane>
                </Tabs>
            </Card>
        </div>
    );
};

export default SchoolDetail;